package com.elecbook.auth.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;

import java.io.IOException;
import java.io.InputStream;

public class RedissionConfig {
    public static RedissonClient getRedissonClientDefault() {
        Config config = new Config();
        config.useSingleServer().setAddress("redis://127.0.0.1:6379").setPassword("123456").setDatabase(1);
        RedissonClient redisson = Redisson.create(config);
        return redisson;
    }

    public static RedissonClient getRedissonClientYaml() {
        Config config = null;
        try {
            // 实际书写中，建议使用类路径来进行文件路径加载
            InputStream inputStream = RedissionConfig.class.getClassLoader().getResourceAsStream("redission-config.yaml");
            config = Config.fromYAML(inputStream);
        } catch (IOException e) {
            throw new RuntimeException("读取RedissonClient配置文件异常");
        }
        return Redisson.create(config);
    }
}
